﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Synchronization.Data.SqlServer;
using System.Data.SqlClient;
using System.ServiceModel;

namespace Infrastructure.WpfClient.Accessibility
{

    [ServiceBehavior()]
    public class RelationalSyncContractService : IRelationalSyncContract
    {
        private SqlSyncProvider _provider ;
        public RelationalSyncContractService()
        {
            var serverConn = new SqlConnection("Data Source=skynetlibrary;Initial Catalog=SkyNetLibrary;Integrated Security=True;MultipleActiveResultSets=True;");
            _provider =  new SqlSyncProvider("Skynet", serverConn, null, "Sync");
        }
        public void BeginSession(Microsoft.Synchronization.SyncProviderPosition position, Microsoft.Synchronization.SyncSessionContext syncSessionContext)
        {
            this._provider.BeginSession(position, syncSessionContext);
        }

        public void EndSession(Microsoft.Synchronization.SyncSessionContext syncSessionContext)
        {
            this._provider.EndSession(syncSessionContext);
        }
        public Microsoft.Synchronization.ChangeBatch GetChangeBatch(uint batchSize, Microsoft.Synchronization.SyncKnowledge destinationKnowledge, out object changeDataRetriever)
        {
            return this.GetChangeBatch(batchSize, destinationKnowledge, out changeDataRetriever);   
        }
        public Microsoft.Synchronization.FullEnumerationChangeBatch GetFullEnumerationChangeBatch(uint batchSize, Microsoft.Synchronization.SyncId lowerEnumerationBound, Microsoft.Synchronization.SyncKnowledge knowledgeForDataRetrieval, out object changeDataRetriever)
        {
            return this.GetFullEnumerationChangeBatch(batchSize, lowerEnumerationBound, knowledgeForDataRetrieval, out changeDataRetriever);
        }
        public void GetSyncBatchParameters(out uint batchSize, out Microsoft.Synchronization.SyncKnowledge knowledge)
        {
            this.GetSyncBatchParameters(out batchSize, out knowledge);
        }
        public Microsoft.Synchronization.SyncIdFormatGroup GetIdFormats()
        {
            return this.GetIdFormats(); 
        }
        public void ProcessChangeBatch(Microsoft.Synchronization.ConflictResolutionPolicy resolutionPolicy, Microsoft.Synchronization.ChangeBatch sourceChanges, object changeDataRetriever, Microsoft.Synchronization.SyncCallbacks syncCallbacks, Microsoft.Synchronization.SyncSessionStatistics sessionStatistics)
        {
            this.ProcessChangeBatch(resolutionPolicy, sourceChanges, changeDataRetriever, syncCallbacks, sessionStatistics);
        }
        public void ProcessFullEnumerationChangeBatch(Microsoft.Synchronization.ConflictResolutionPolicy resolutionPolicy, Microsoft.Synchronization.FullEnumerationChangeBatch sourceChanges, object changeDataRetriever, Microsoft.Synchronization.SyncCallbacks syncCallbacks, Microsoft.Synchronization.SyncSessionStatistics sessionStatistics)
        {
            this.ProcessFullEnumerationChangeBatch(resolutionPolicy, sourceChanges, changeDataRetriever, syncCallbacks, sessionStatistics); 
        }        
    }
}
